#!/bin/bash

#------------------------------------------------------------------------------
#Filename:	74805-passwordlength.sh
#Version:	1.1
#Date:		2013/06/18
#Author:	yuanhui.shi
#Email:		yuanhui.shi@cs2c.com.cn
#Summary:	02.01系统核心功能-06基本命令行工具-12passwd工具-03合法密码长度
#Notes:		证明用户密码长度最少为8位
#Copyright:	China Standard Software Co.,Ltd.
#History:
#		Version 1.0,2013/06/18
#		-The first one
#		Version 1.1,2013/09/03
#		-Modify the script to satisfy the shell standard
#		Version 1.2,2013/09/04
#		-Call public function Ssh
#------------------------------------------------------------------------------


PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
export PATH

source ../../lib/Echo.sh
source ./lib/Ssh.sh

function CleanData ()
{
  EchoInfo "测试完成后，恢复数据。"
  rm -rf /tmp/tmp.results
  rm -rf /tmp/tmp.results1

  userdel -r test

  EchoInfo "74805-passwd.sh测试完毕"
}

trap "CleanData" EXIT

EchoInfo "首先为test设置密码为8为'qwer1234'："
Adduser "test" "qwer1234"

EchoInfo "更改用户test密码为6位'qwe123'或者8位'asdf1234',查看是否修改成功"

/usr/bin/expect << \EOF
spawn passwd test
expect "Enter new password:"
send "qwe123\r"
expect "Weak password:too short!Enter new password:"
send "asdf1234\r"
expect "Re-type new password:"
send "asdf1234\r" 
expect eof
EOF

Ssh "test" "127.0.0.1" "asdf1234" "pwd >/tmp/tmp.results"
test `cat /tmp/tmp.results` == "/home/test" 
EchoResult "密码修改成功，密码为asdf1234" 


EchoInfo "密码修改为超过8位，并且检验是否修改成功！"

/usr/bin/expect << \EOF
spawn passwd test
expect "Enter new password:"
send "qwer12345\r" 
expect "Re-type new password:"
send "qwer12345\r"
expect eof
EOF

Ssh "test" "127.0.0.1" "qwer12345" "pwd >/tmp/tmp.results1"
test `cat /tmp/tmp.results1` == "/home/test" 
EchoResult "密码修改成功，密码为qwer12345" 
